<!--
 * @Description:支付场景 记录
-->
<template>
  <div class="registered-container business appMainWarp">
    <el-form :inline="true" :model="searchKey" class="demo-form-inline">

      <el-form-item label="院区:">
        <el-select v-model="searchKey.hospital_area_no" placeholder="请选择">
          <el-option
            v-for="item in searchKey.Hospital"
            :key="item.area_code"
            :label="item.area_name"
            :value="item.area_code"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="支付场景订单号:">
        <el-input v-model="searchKey.order_no" placeholder="请输入支付场景订单号" @change="suborder_no" />
      </el-form-item>

      <el-form-item label="交易类型:">
        <el-select v-model="searchKey.trans_type" placeholder="请选择">
          <el-option
            v-for="item in searchKey.compensationWayList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="选择支付场景:">
        <el-select v-model="searchKey.system_no" multiple placeholder="请选择支付场景" clearable>
          <el-option
            v-for="item in searchKey.System"
            :key="item.pay_scene_no"
            :label="item.pay_scene_name"
            :value="item.pay_scene_no"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="业务类型:">
        <el-cascader
          v-model="searchKey.bill_type"
          :options="searchKey.BillType"
          :props="props"
          change-on-select
          clearable
        />
      </el-form-item>

      <el-form-item label="支付方式:">
        <el-select v-model="searchKey.pay_style" placeholder="请选择">
          <el-option
            v-for="item in searchKey.PayStyle"
            :key="item.pay_no"
            :label="item.name"
            :value="item.pay_no"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="患者ID:">
        <el-input v-model="searchKey.patient" placeholder="请输入患者ID" />
      </el-form-item>
      <el-form-item label="操作员编号:">
        <el-input v-model="searchKey.operator" placeholder="请输入操作员编号" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="onLoad">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="success" icon="el-icon-download" @click="onExport">导出</el-button>
      </el-form-item>
    </el-form>

    <template>
      <el-table
        ref="table"
        v-loading="page.tableLoading"
        v-el-height-adaptive-table="{bottomOffset: 90}"
        max-height="500px"
        center
        class="table"
        :data="searchData"
        stripe
        border
      >
        <el-table-column type="index" width="70" label="序号" />
        <el-table-column label="交易类型" align="center">
          <template slot-scope="scope">{{ scope.row.trans_type||'-' }}</template>
        </el-table-column>
        <el-table-column label="患者ID" align="center">
          <template slot-scope="scope">{{ scope.row.patient_id ||'-' }}</template>
        </el-table-column>
        <!-- <el-table-column label="患者类型" align="center">
          <template slot-scope="scope">{{ scope.row.pay_type_name||'-' }}</template>
        </el-table-column> -->
        <el-table-column label="订单号" align="center">
          <template slot-scope="scope">{{ scope.row.self_order_no||'-' }}</template>
        </el-table-column>
        <!-- <el-table-column label="交易流水号" align="center">
          <template slot-scope="scope">{{ scope.row.transcation_id||'-' }}</template>
        </el-table-column> -->
        <el-table-column label="交易金额" align="center">
          <template slot-scope="scope">{{ scope.row.pay_fee||'-' }}</template>
        </el-table-column>
        <el-table-column label="交易时间" align="center">
          <template slot-scope="scope">{{ scope.row.trans_time||'-' }}</template>
        </el-table-column>
        <el-table-column label="交易院区" align="center">
          <template slot-scope="scope">{{ scope.row.hospital_area_no||'-' }}</template>
        </el-table-column>

        <el-table-column label="支付场景(自助机)" align="center" width="110">
          <template slot-scope="scope">
            {{ scope.row.hospital_area_no||'-' }}
          </template>
        </el-table-column>

        <!-- <el-table-column v-if="system == '200'" label="支付场景(线上平台)" align="center" width="110">
          <template slot-scope="scope">
            {{ scope.row.system_no == 100 ? '融威自助机' : scope.row.system_no == 200 ? '线上平台' :'-' }}
          </template>
        </el-table-column> -->

        <el-table-column label="操作员编号" align="center">
          <template slot-scope="scope">{{ scope.row.operator_id ||'-' }}</template>
        </el-table-column>
        <el-table-column label="业务类型" align="center">
          <template slot-scope="scope">{{ scope.row.bill_type_no||'-' }}</template>
        </el-table-column>
        <el-table-column label="支付方式" align="center">
          <template slot-scope="scope">{{ scope.row.pay_style_no||'-' }}</template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope"><el-button type="primary" @click="detailsView(scope.row)">查看详情</el-button></template>
        </el-table-column>
      </el-table>
    </template>
    <pagination
      :total="page.totalRow"
      :page.sync="page.currentPage"
      :limit.sync="page.pageSize"
      @pagination="onSearch"
    />

  </div>
</template>

<script>
import elHeightAdaptiveTable from '@/directive/el-table'
import { getConfigType, recordScene } from '@/api/transactRecords/index'
import Pagination from '@/components/Pagination' // 分页

export default {
  name: 'PaySceneRecord',
  components: {
    Pagination
  },
  directives: { elHeightAdaptiveTable },
  data() {
    return {
      quaflat: 0, // 按钮默认
      searchKey: {
        time: '', // 时间
        order_no: '', // 订单号
        hospital_area_no: '', // 选择院区
        Hospital: [],
        trans_type: 0, // 交易类型
        compensationWayList: [
          { id: 0, name: '全部' },
          { id: 1, name: '正交易' },
          { id: 2, name: '负交易' }
        ],
        system_no: '', // 选择平台
        System: [],
        pay_style: '', // 支付方式
        PayStyle: [],
        bill_type: [], // 业务类型
        BillType: [],
        operator: '',
        patient: ''
      },
      props: {
        label: 'name',
        value: 'bill_no',
        children: 'child'
      },
      start_time: '',
      end_time: '',

      searchData: [],

      page: {
        tableLoading: false,
        currentPage: 1, // 当前页
        pageSize: 20, // 默认条数
        totalRow: 0, // 总条数
        totalPage: 0 // 总页数
      },
      pickerOptions: { // 日期不能点击
        disabledDate(time) {
          return time.getTime() > Date.now()
        }
      },
      system: {}
    }
  },

  created() {
    this.searchKey.time = this.utils.getDay(0, '-')
  },
  mounted() {
    this.getConfig()
    this.onLoad()
  },
  methods: {
    // 系统配置搜索
    getConfig() {
      var that = this
      var params = {}
      getConfigType(params).then(res => {
        that.searchKey.Hospital = res.data.hospital// 院区
        that.searchKey.PayStyle = res.data.payment // 支付方式
        that.searchKey.System = res.data.scene// 场景
        that.searchKey.BillType = res.data.bill// 业务类型
      })
        .catch(() => {
        })
    },
    // 递归判断列表，把最后的children的内容不显示
    getTreeData(data) {
      for (var i = 0; i < data.length; i++) {
        if (data[i].data.length < 1) {
          // children若为空数组，则将children设为undefined
          data[i].data = undefined
        } else {
          // children若不为空数组，则继续 递归调用 本方法
          this.getTreeData(data[i].data)
        }
      }
      return data
    },
    // 查询列表
    onLoad() {
      this.page.currentPage = 1
      this.onSearch()
    },
    onSearch() {
      var params = {}
      var that = this
      params.page = that.page.currentPage // 当前页数
      params.limit = that.page.pageSize // 每页展示条数
      if (that.searchKey.time && that.searchKey.time.length > 0) {
        params.startime = that.searchKey.time
        params.endtime = that.searchKey.time
      } else {
        params.startime = ''
        params.endtime = ''
      }
      params.billno	 = that.searchKey.bill_type.length > 1 ? that.searchKey.bill_type[1] : that.searchKey.bill_type[0] || ''
      params.hospital = that.searchKey.hospital_area_no
      params.orderno = that.searchKey.order_no
      params.trans = that.searchKey.trans_type
      params.sceneno = that.searchKey.system_no.toString()
      params.payno = that.searchKey.pay_style
      params.patient = that.searchKey.patient
      params.operator = that.searchKey.operator
      that.page.tableLoading = true
      // var loginInit = that.$loading()
      recordScene(params)
        .then(res => {
          that.page.tableLoading = false
          that.searchData = res.data.result
          // that.system = res.data.system_no
          that.page.totalPage = res.data.pages
          that.page.totalRow = parseInt(res.data.count)
        })
        .catch(() => {
          that.page.tableLoading = false
        })
    },
    // 导出
    onExport() {
      var params = {}
      var that = this
      params.page = that.page.currentPage // 当前页数
      params.limit = that.page.pageSize // 每页展示条数
      if (that.searchKey.time && that.searchKey.time.length > 0) {
        params.startime = that.searchKey.time[0]
        params.endtime = that.searchKey.time[1]
      } else {
        params.startime = ''
        params.endtime = ''
      }
      params.billno	 = that.searchKey.bill_type.length > 1 ? that.searchKey.bill_type[1] : that.searchKey.bill_type[0] || ''
      params.hospital = that.searchKey.hospital_area_no
      params.orderno = that.searchKey.order_no
      params.trans = that.searchKey.trans_type
      params.sceneno = that.searchKey.system_no.toString()
      params.payno = that.searchKey.pay_style
      params.patient = that.searchKey.patient
      params.operator = that.searchKey.operator
      var viewUrl = `/cms/recordScene?&page=${params.page}&limit=${params.limit}&billno=${params.billno}&hospital=${params.hospital}&orderno=${
        params.orderno
      }&trans=${params.trans}&startime=${
        params.startime
      }&endtime=${params.endtime}&sceneno=${params.sceneno}&payno=${params.payno}&patient=${params.patient}&operator=${params.operator}&export=${1}`
      window.location.href = process.env.VUE_APP_BASE_API + viewUrl
    },
    // 验证订单号
    suborder_no() {
      const id = this.searchKey.order_no
      const reg = /^[0-9a-zA-Z]+$/
      if (!reg.test(id)) {
        this.$message({
          type: 'warning',
          message: '请输入正确的订单号'
        })
        this.searchKey.order_no = ''
        return false
      }
    },
    getlisttable(flat) {
      this.quaflat = flat
      if (this.quaflat === 0) {
        this.date = 'yesterday'
        this.searchKey.time = this.utils.Foryest()
        this.onLoad()
      } else if (this.quaflat === 1) {
        this.date = 'sevenday'
        this.searchKey.time = this.utils.Forseven()
        this.onLoad()
      } else {
        this.date = 'month'
        this.searchKey.time = this.utils.Formonth()
        this.onLoad()
      }
    },
    detailsView(item) {
      this.$router.push({
        path: '/transactRecords/detailsRecords/index',
        query: {
          id: item.id,
          type: 'self'
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.business {
  // position: relative;
  // width: 100%;
  .demo-form-inline {
    .el-button--primary {
      background-color: #579ef8 !important;
      color: #fff !important;
    }
   .el-button {
      background-color: #e8f4ff;
      color: #579ef8;
      border: 1px solid rgba(87, 158, 248, 1);
    }
  }

}
</style>

